<?php
	/**
	* Survey data modeller
	*/
	class surveymodule_cat{
		public static function question_default_object(){
			$obj=null;
			$obj->id_survey="";
			$obj->name_question="";
			$obj->location_data="";
			$obj->rank=0;
			$obj->amount_answer = 0;
			return $obj;
		}
		function question_update($values,$object) {
			$object->id_survey = $values['id_survey'];
			$object->name_question = $values['name_question'];
			return $object;
		}
		function question_form($object, $survey) {
			if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
			exponent_forms_initialize();
			$form = new form();
			if (!isset($object->id)) {
				$object = surveymodule_cat::question_default_object();
			} else {
				$form->meta('id',$object->id);
			}
			global $db;

			$sur=$db->selectDropdown('surveymodule_table_survey','name_survey',"location_data = '{$survey->location_data}'");

			$form->register('name_question','Name Question',new textcontrol($object->name_question));
			$form->register('id_survey','Survey',new dropdowncontrol($object->id_survey,$sur));

			$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
			return $form;
		}

		function cat_survey_form($cat_survey) {
			if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
			global $db;
			exponent_forms_initialize();
			$form = new form();
			if (!isset($cat_survey->id)) {
				$cat_survey->name = '';
				$cat_survey->seo_name = '';
				$cat_survey->search_des='';
				$cat_survey->is_active =1;
				$cat_survey->file_id =0;
			} else {
				$form->meta('id',$cat_survey->id);
			}

			$form->register('name','Category name',new textcontrol($cat_survey->name));
			$form->register('search_des','Search Description (for SEO)',new textcontrol($cat_survey->search_des));
			$form->register('seo_name','Seo Name (leave blank for automatic generate)',new textcontrol($cat_survey->seo_name));
			$form->register('file_id','Thumbnail', new ajax_select_file("file_id",0,$cat_survey->file_id,true));
			$form->register("is_active","Active", new checkboxcontrol($cat_survey->is_active));
			$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
			return $form;
		}
		
		function cat_survey_update($values,$object) {
			$object->name = $values['name'];
			//$object->seo_name = $values['search_des'];
			$object->search_des=$values['search_des'];
			if (isset($values['is_active']))
				$object->is_active =1;
			else
				$object->is_active =0;
			$object->file_id =intval($values['file_id']);

			$object->seo_name = $values['seo_name'];
			if (trim($object->seo_name) == "")
				$object->seo_name = _to_vietnamese_with_nomark($values['name']);
			else
				$object->seo_name = _to_vietnamese_with_nomark($values['seo_name']);
			
			if (isset($object->id))
				$object->seo_name = _ab_check_seoname("surveymodule_catergory",$object->seo_name,$object->id);
			else
				$object->seo_name = _ab_check_seoname("surveymodule_catergory",$object->seo_name);
			
			return $object;
		}
		
		
		function company_form($company) {
			if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
			global $db;
			exponent_forms_initialize();
			$form = new form();
			if (!isset($company->id)) {
				$company->name = '';
				$company->seo_name = '';
				$company->description='';
				$company->is_active =1;
				$company->file_id =0;
			} else {
				$form->meta('id',$company->id);
			}

			$form->register('name','Company name',new textcontrol($company->name));
			$form->register('seo_name','Seo Name (leave blank for automatic generate)',new textcontrol($company->seo_name));
			$form->register('description','Description',new texteditorcontrol($company->description));
			$form->register('file_id','Thumbnail', new ajax_select_file("file_id",0,$company->file_id,true));
			$form->register("is_active","Active", new checkboxcontrol($company->is_active));
			$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
			return $form;
		}
		
		function company_update($values,$object) {
			$object->name = $values['name'];
			//$object->seo_name = $values['search_des'];
			$object->description=$values['description'];
			if (isset($values['is_active']))
				$object->is_active =1;
			else
				$object->is_active =0;
			$object->file_id =intval($values['file_id']);

			$object->seo_name = $values['seo_name'];
			if (trim($object->seo_name) == "")
				$object->seo_name = _to_vietnamese_with_nomark($values['name']);
			else
				$object->seo_name = _to_vietnamese_with_nomark($values['seo_name']);
			
			if (isset($object->id))
				$object->seo_name = _ab_check_seoname("surveymodule_catergory",$object->seo_name,$object->id);
			else
				$object->seo_name = _ab_check_seoname("surveymodule_catergory",$object->seo_name);
			
			return $object;
		}
		
		/**
		* Return survey default object
		* 
		*/
		function survey_getDefaultObject(){
			$survey = null;
			$survey->cat_id = 0;
			$survey->time_start =time();
			$survey->time_end = $survey->time_start ;
			$survey->name = "";                    
			$survey->location_data = "";
			$survey->user_id = 0;
			$survey->seo_name = 0;
			$survey->is_active =0;
			$survey->description = "";
			$survey->first_text="";
			$survey->view_count = 0;
			$survey->finished_count =0;                                   
			$survey->facebook_shared=0;
			$survey->twitter_shared=0;                                    
			return $survey;
		}
		
		function survey_update($values,$object) {
			$day_start = $values['day_start'];
			$month_start = $values['month_start'];
			$year_start = $values['year_start'];
			$time_start = $year_start.'-'.$month_start.'-'.$day_start;

			$day_finished = $values['day_end'];
			$month_finished = $values['month_end'];
			$year_finished = $values['year_end'];
			$time_end = $year_finished.'-'.$month_finished.'-'.$day_finished;

			$object->id_catergory = $values['cat_sur'];
			$object->name_survey = $values['name_survey'];
			$object->time_start = $time_start;
			$object->time_end = $time_end;
			//$object->amount_question = $values['amount_question'];
			return $object;
		}
	}
	
?>
